import axios from 'axios' // 导入axios
import store from '@/store'

const request = axios.create({
  baseURL: process.env.VUE_APP_API
})
// 请求拦截器
request.interceptors.request.use(
  function (config) {
    if(store.getters['user/token']){
      config.headers.Authorization=store.getters['user/token']
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)
// 响应拦截器
request.interceptors.response.use(function (response) {
  // 一定要 return response
  return response
}, function (error) {
  return Promise.reject(error)
})

export default request // 将该实例共享出去